/*var Main = {
	data() {
		return {
			activeIndex: '1'
		};
	},
	methods: {
		handleSelect(key, keyPath) {
			console.log(key, keyPath);
		}
	}
}
var Ctor = Vue.extend(Main)
new Ctor().$mount('#app1')*/

var Main = {
	data() {
		return {
			allrepairoptions: [{
				value: '选项1',
				label: '全部数据'
			}, {
				value: '选项2',
				label: '接件'
			}, {
				value: '选项3',
				label: '待检测'
			}, {
				value: '选项4',
				label: '待与客户确认'
			}, {
				value: '选项5',
				label: '待维修'
			}, {
				value: '选项6',
				label: '待沟通'
			}, {
				value: '选项7',
				label: '维修中'
			}, {
				value: '选项8',
				label: '待交付'
			}, {
				value: '选项9',
				label: '已交付'
			}],
			selectRepairInfo: '',
			gdID: ''
		}
	},
	methods: {
		//根据选项获取表单数据
		getSelectRepairInfo(){
			var _this=this;
			console.log("搜索数据："+_this.selectRepairInfo);
		}
	}
}
var Ctor = Vue.extend(Main)
new Ctor().$mount('#app2')


/* 遮罩层 */
var Main = {
	data() {
		return {
			repform: {
				getPerson: '',
				custid: '',
				contactid: '',
				phone: '',
				repname: '',
				gdchlassity: '',
				reptel: '',
				proID: '',
				getman: '',
				texterrorDescription:'',
				textcommunication:'',
				radioguarantee:'',
				alljindu:'',
				rocost:'',
				hasgetcost:'',
				radiostatus:'',
				roprofit:'',
				textcommunication:'',
				gettoday: new Date(),
				gettime: new Date(),
				prosalettoday: new Date(),
				paytoday: new Date(),
			},
			customer:[],
			customers:[],
			firsgettman:[],
			firsgettmans:[],
			cclassify:[],
			cclassifies:[],
			allcontact:[],
			allcontacts:[],
			allgdchlassity: [],
			allgdchlassitys: [],
			proIDoption: [],
			proIDoptions: [],
			getmanoption: [],
			getmanoptions: [],
			alljinduoption: [],
			alljinduoptions: [],
			addcusttel:[],
			addcontel:[],
			dialogFormVisible: false,
			cumloading:false,
			dialogFormVisible: false,
			reprules: {
				custid: [{
					required: true,
					message: '请选择对应客户',
					trigger: 'change'
				}],
				proID: [{
					required: true,
					message: '请选择维修产品',
					trigger: 'change'
				}],
				getman: [{
					required: true,
					message: '请选择承接人',
					trigger: 'change'
				}],
				radiostatus:[{
					required: true,
					message: '请选择状态',
					trigger: 'change'
				}]
			},
			/* 销售日期选择 */
			pickerOptions1: {
				disabledDate(time) {
					return time.getTime() > Date.now();
				},
				shortcuts: [{
					text: '今天',
					onClick(picker) {
						picker.$emit('pick', new Date());
					}
				}, {
					text: '昨天',
					onClick(picker) {
						const date = new Date();
						date.setTime(date.getTime() - 3600 * 1000 * 24);
						picker.$emit('pick', date);
					}
				}, {
					text: '一周前',
					onClick(picker) {
						const date = new Date();
						date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
						picker.$emit('pick', date);
					}
				}]
			},
			/* 交付日期选择 */
			pickerOptions: {
				disabledDate(time) {
					return time.getTime() < Date.now();
				},
				shortcuts: [{
					text: '今天',
					onClick(picker) {
						picker.$emit('pick', new Date());
					}
				}, {
					text: '明天',
					onClick(picker) {
						const date = new Date();
						date.setTime(date.getTime() + 3600 * 1000 * 24);
						picker.$emit('pick', date);
					}
				}, {
					text: '一周后',
					onClick(picker) {
						const date = new Date();
						date.setTime(date.getTime() + 3600 * 1000 * 24 * 7);
						picker.$emit('pick', date);
					}
				}]
			},
			
		};
	},
	methods:{
		//获取数据（新建打开遮罩层）
		getNew(){
			var _this=this;
			this.dialogFormVisible=true;
			axios.post("/aftersale/chooseAllRepairOptions",
					//id:
					//ajax请求成功的回调函数
				).then(function(v) {
					console.log("回调成功，获取了服务器端返回的值v");
					console.log(v);
					//获取接单人
					_this.firsgettman= v.data.getPerson.map(item => {
						return { value: item.ID, label: item.name };
					});
					_this.firsgettmans=_this.firsgettman;
					//获取客户
					_this.customers= v.data.custid.map(item => {
						return { value: item.ID, label: item.name };
					});
					_this.customer=_this.customers;
					//alert(v.data.custid);
					//alert(_this.addcusttel);
					//把客户信息给新对象
					_this.addcusttel=v.data.custid;
					//获取工单分类
					_this.allgdchlassitys=v.data.classityRepair.map(item =>{
						return { value: item.dictId, label: item.dictName };
					});
					_this.allgdchlassity=_this.allgdchlassitys;
					console.log("所有工单分类");
					console.log(_this.allgdchlassity);
					//获取产品
					_this.proIDoptions=v.data.allProduce.map(item =>{
						return { value: item.ID, label: item.name };
					});
					_this.proIDoption=_this.proIDoptions;
					//获取承接人
					_this.getmanoptions=v.data.getPerson.map(item =>{
						return { value: item.ID, label: item.name };
					});
					_this.getmanoption=_this.getmanoptions;
					
				})/*.catch(function() {
					alert("出错了");
				})*/;
		},
		 //加载界面客户
		cumremoteMethod(query) {
			var _this=this;
		      if (query !== '') {
		        this.cumloading = true;
		        setTimeout(() => {
		          this.cumloading = false;
		          this.customer = _this.customers.filter(item => {
		            return item.label.toLowerCase()
		              .indexOf(query.toLowerCase()) > -1;
		          });
		        }, 200);
		      } else {
		        this.uosign = [];
		      }
		    },
		    //清空客户及对应信息
		    comcustidto(){
				var _this=this;
				_this.customer=_this.customers;
				_this.repform.phone='';
				_this.repform.contactid='';
				_this.repform.repname='';
				_this.repform.reptel='';
			},
			 //清空联系人及对应信息
			comcontidto(){
				var _this=this;
				_this.allcontact=_this.allcontacts;
				_this.repform.contactid='';
				_this.repform.reptel='';
			},
			//选择客户查询对应的联系人
			selectOnechange(){
				//选择客户加载联系方式
				var _this=this;
				//alert(_this);
				_this.addcusttel.map(item =>{
					if (_this.repform.custid==item.ID) {
						_this.repform.phone=item.phone;
					}
				});
				//alert(_this.repform.custid);
				console.log(_this.repform.custid);
				axios.post("/aftersale/custTocon",
				Qs.stringify({
				'custid':_this.repform.custid
				}
				,{arrayFormat: 'brackets'})
				).then(function(v){					          				
				console.log("回调成功，获取了服务器端返回的值v");
				console.log(v.data.comcustmanid);
				_this.allcontact= v.data.comcustmanid.map(item => {
					return { value: item.ID, label: item.name };
				}); 
					_this.addcontel=v.data.comcustmanid;
				//_this.orderes
				})/*.catch(function(){
				  console.log("信息出错了");
				})*/;			
			},
			//选择联系人加载联系人信息
			addothercon:function(){
				var _this=this;
				_this.addcontel.map(item =>{
					if(_this.repform.contactid==item.ID){
						_this.repform.reptel=item.phone;
						_this.repform.repname=item.name;
					}
				});
			},
			//接单人
			firstmanMethod(query){
				var _this=this;
						if (query !== '') {
							this.cumloading = true;
							setTimeout(() => {
								this.cumloading = false;
								this.firsgettman = _this.firsgettmans.filter(item => {
									return item.label.toLowerCase()
										.indexOf(query.toLowerCase()) > -1;
								});
							}, 200);
						} else {
							this.uosign = [];
						}
			},
			//加载联系人
			contactidMethod(query) {
				var _this=this;
				if (query !== '') {
					this.cumloading = true;
					setTimeout(() => {
						this.cumloading = false;
						this.allcontact = _this.allcontacts.filter(item => {
							return item.label.toLowerCase()
							.indexOf(query.toLowerCase()) > -1;
						});
					}, 200);
				} else {
					this.uosign = [];
				}
			},
			//加载工单分类
			gdchlassityMethod(query){
				var _this=this;
				//console.log(_this);
				if (query !== '') {
					this.cumloading = true;
					setTimeout(() => {
						this.cumloading = false;
						this.allgdchlassity = _this.allgdchlassitys.filter(item => {
							return item.label.toLowerCase()
							.indexOf(query.toLowerCase()) > -1;
						});
					}, 200);
					
				} else {
					this.uosign = [];
				}
			},
			//加载产品
			productidMethod(query){
				var _this=this;
				if (query !== '') {
					this.cumloading = true;
					setTimeout(() => {
						this.cumloading = false;
						this.proIDoption = _this.proIDoptions.filter(item => {
							return item.label.toLowerCase()
							.indexOf(query.toLowerCase()) > -1;
						});
					}, 200);
				} else {
					this.uosign = [];
				}
			},
			//加载承接人
			getmanMethod(query){
				var _this=this;
				if (query !== '') {
					this.cumloading = true;
					setTimeout(() => {
						this.cumloading = false;
						this.getmanoption = _this.getmanoptions.filter(item => {
							return item.label.toLowerCase()
							.indexOf(query.toLowerCase()) > -1;
						});
					}, 200);
				} else {
					this.uosign = [];
				}
			},
			submitForm(repform) {
				//验证方法
				//alert("添加！");
				var _this=this;
				this.$refs[repform].validate((valid) => {
					if (valid) {
						//post提交数据
						axios.post("/aftersale/addrepair",
							//参数转换
							Qs.stringify(this.comform, {
								arrayFormat: 'brackets'
							})
							//id:
							//ajax请求成功的回调函数
						).then(function(v) {
							console.log("回调成功，获取了服务器端返回的值v");
							console.log(v);
							  _this.$message({
			           			showClose: true,
								type: 'success',
								message: '添加成功!',
								duration:3000,
								center: true
							});
			           		//延时两秒刷新
			           		setTimeout(function (){
			           			window.location.href = '/aftersale/repair';
			           		}, 2000);
						}).catch(function() {
							//alert("出错了");
							_this.$message({
			           			showClose: true,
								type: 'success',
								message: '添加失败!',
								duration:3000,
								center: true
							});
						});
					} else {
						console.log('error submit!!');
						return false;
					}
				});
		},
		resetForm(formName) {
			this.$refs[formName].resetFields();
		}
		
	}
};
var Ctor = Vue.extend(Main)
new Ctor().$mount('#app3')



/*  表单  */
var Main = {
	data() {
		return {
			repairtable:repairlist,
			/*repairtable: [{
				ID: '20161123',
				theme: 'sdfsdfsgdf',
				custName: '张三',
				cost: '500.00',
				getCost: '300.00',
				statusName: '执行中',
				getpersonName: 'rose',
				profile: '0.00'
			}, {
				ID: '20160903',
				theme: 'sdfsdfsgdf',
				custName: '王小虎',
				cost: '500.00',
				getCost: '300.00',
				statusName: '执行中',
				getpersonName: 'rose',
				profile: '0.00'
			}],*/
			repform: {
				getPerson: '',
				custid: '',
				conid: '',
				phone: '',
				repname: '',
				gdchlassity: '',
				reptel: '',
				proID: '',
				getman: '',
				texterrorDescription:'',
				textcommunication:'',
				radioguarantee:'',
				alljindu:'',
				rocost:'',
				hasgetcost:'',
				radiostatus:'',
				roprofit:'',
				remark:'',
				gettoday: '',
				gettime: '',
				prostarttoday: '',
				prosalettoday: '',
				paytoday:''
			},
			dialogDelete:false,
			pages: pageinfo,
			currentPage4: pageinfo.pageNum,
			multipleSelection: [],
			customer:[],
			customers:[],
			firsgettman:[],
			firsgettmans:[],
			cclassify:[],
			cclassifies:[],
			allcomcustmanid:[],
			allcomcustmanids:[],
			allcomspendtime:[],
			allcomspendtimes:[],
			proIDoption: [],
			proIDoptions: [],
			getmanoption: [],
			getmanoptions: [],
			alljinduoption: [],
			alljinduoptions: [],
			dialogFormVisible: false,
			cumloading:false,
			reprules: {
				custid: [{
					required: true,
					message: '请选择对应客户',
					trigger: 'change'
				}],
				proID: [{
					required: true,
					message: '请选择维修产品',
					trigger: 'change'
				}],
				getman: [{
					required: true,
					message: '请选择承接人',
					trigger: 'change'
				}],
				radiostatus:[{
					required: true,
					message: '请选择状态',
					trigger: 'change'
				}]
			},
			/* 日期选择 */
			pickerOptions1: {
				disabledDate(time) {
					return time.getTime() > Date.now();
				},
				shortcuts: [{
					text: '今天',
					onClick(picker) {
						picker.$emit('pick', new Date());
					}
				}, {
					text: '昨天',
					onClick(picker) {
						const date = new Date();
						date.setTime(date.getTime() - 3600 * 1000 * 24);
						picker.$emit('pick', date);
					}
				}, {
					text: '一周前',
					onClick(picker) {
						const date = new Date();
						date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
						picker.$emit('pick', date);
					}
				}]
			},
		};
	},
	methods:{
		submitForm(formName) {
			this.$refs[formName].validate((valid) => {
				if (valid) {
					alert('submit!');
				} else {
					console.log('error submit!!');
					return false;
				}
			});
		},
		resetForm(formName) {
			this.$refs[formName].resetFields();
		},
		//打开编辑工单遮罩层
		updatehandleClick(row) {
			this.dialogFormVisible = true;
		},
		//打开维修工单视图
		openrepairView(row){
			window.open("/aftersale/openRepairView?id="+row.ID);
		},
		handleClick(row) {
			console.log(row);
		},
		handleSelectionChange(val) {
			this.multipleSelection = val;
		},
		/*handleSizeChange(val) {
			console.log(`每页 ${val} 条`);
		},
		handleCurrentChange(val) {
			console.log(`当前页: ${val}`);
		},*/
		
		handleSizeChange(val) {
			window.location.href = '/aftersale/repair?pageSize=' + val;

		},
		handleCurrentChange(val) {
			window.location.href = '/aftersale/repair?pageNum=' + val;
		},
		deletenew(ID){
			this.ID=ID;
			this.dialogDelete=true;
		},
		//更新维修工单信息
		updatehandleClick(row) {
			var _this = this;
			var id= row;
			console.log(_this);
			console.log(row);
			axios.post("/aftersale/repairOne",
				Qs.stringify( {
			   			'ID':row.ID,
				   },{arrayFormat: 'brackets'}) 

			).then(function(v) {
				console.log("回调成功，获取了服务器端返回的值v");
				console.log(v.data);
				//获取接单人
				_this.firsgettman= v.data.getPerson.map(item => {
					return { value: item.ID, label: item.name };
				});
				_this.firsgettmans=_this.firsgettman;
				//获取客户
				_this.customers= v.data.custid.map(item => {
					return { value: item.ID, label: item.name };
				});
				_this.customer=_this.customers;
				//alert(v.data.custid);
				//alert(_this.addcusttel);
				//把客户信息给新对象
				_this.addcusttel=v.data.custid;
				//获取工单分类
				_this.allgdchlassitys=v.data.classityRepair.map(item =>{
					return { value: item.dictId, label: item.dictName };
				});
				_this.allgdchlassity=_this.allgdchlassitys;
				console.log("所有工单分类");
				console.log(_this.allgdchlassity);
				//获取产品
				_this.proIDoptions=v.data.allProduce.map(item =>{
					return { value: item.ID, label: item.name };
				});
				_this.proIDoption=_this.proIDoptions;
				//获取承接人
				_this.getmanoptions=v.data.getPerson.map(item =>{
					return { value: item.ID, label: item.name };
				});
				_this.getmanoption=_this.getmanoptions;
				//传值
				console.log(v.data.allcomplaint);
				_this.repform.ID=v.data.repair.ID;
				
				
			})/* .catch(function() {
				alert("出错了");
			} )*/;
			//this.selectOnechange();
			this.dialogFormVisible = true;
		},
		//删除方法
		Delete(){
			var _this=this;
			axios.get("/aftersale/deleteOneRepair",
           			{
						params:{
							ID:_this.ID
						}
           			}
          			).then(function(response){					          				
           			console.log("回调成功，获取了服务器端返回的值v");
           			console.log(response.data);					           		
           		_this.restaurants=response.data;
           		console.log(response.data.RoStatus);
           		console.log(response.data.RoSchedule);
           		if (response.data.RoStatus!=1438 && response.data.RoSchedule!=1265) {
           			//alert("删除成功！");
               		_this.$message({
               			showClose: true,
    					type: 'success',
    					message: '删除成功!',
    					duration:3000,
    					center: true
    				});
               		//延时两秒刷新
               		setTimeout(function (){
               			window.location.href = '/aftersale/repair';
               		}, 2000);
				} else {
					_this.$message({
               			showClose: true,
    					type: 'error',
    					message: '工单未结束!删除失败!',
    					duration:3000,
    					center: true
    				});
				}
           	}).catch(function(){
           		//alert("删除失败！");
           		_this.$message({
					type: 'error',
					message: '删除失败!',
					duration:3000,
					center: true
				});
           	});	//这个是数据的初始化
	      },
	      downloadfile(){
	    	  window.location.href ="/aftersale/RepairExcelDownloads";
	      },//表单提交修改
			submitForm(repform) {
				//验证方法
				//alert("修改！");
				var _this=this;
				this.$refs[repform].validate((valid) => {
					if (valid) {
						//post提交数据
						axios.post("/aftersale/updaterepair",
							//参数转换
							Qs.stringify(this.repform, {
								arrayFormat: 'brackets'
							})
							//id:
							//ajax请求成功的回调函数
						).then(function(v) {
							console.log("回调成功，获取了服务器端返回的值v");
							console.log(v);
							  _this.$message({
			           			showClose: true,
								type: 'success',
								message: '修改成功!',
								duration:3000,
								center: true
							});
			           		//延时两秒刷新
			           		setTimeout(function (){
			           			window.location.href = '/aftersale/repair';
			           		}, 2000);
						}).catch(function() {
							//alert("出错了");
							_this.$message({
			           			showClose: true,
								type: 'success',
								message: '修改失败!',
								duration:3000,
								center: true
							});
						});
					} else {
						console.log('error submit!!');
						return false;
					}
				});
			},
			resetForm(repform) {
				this.$refs[repform].resetFields();
			}
		
	}
}
var Ctor = Vue.extend(Main)
new Ctor().$mount('#app4')
